using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
namespace Rally_Dekstop
{
    public partial class WorkspaceSelector : Form
    {
        
        string WorkspaceSelected;
        int indexSelected;
        object parent = null;
        public WorkspaceSelector(object listener)
        {
            InitializeComponent();
            parent = listener; 
            if (RallyDesk.CURRENTWORKSPACE.SelectedWorkSpace.Equals(string.Empty))
                this.button2.Enabled = false;
          
            int i = 0;
            for (i = 0; i < RallyDesk.WORKSPACENAMES.Count; i++)
            {
                this.cmb_workspace.Items.Add(RallyDesk.WORKSPACENAMES[i]);
            }
            
        }

        private void WorkspaceSelector_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            if (this.cmb_workspace.Text == string.Empty)
                return;
            if (RallyDesk.CURRENTWORKSPACE.SelectedWorkSpace != cmb_workspace.Text)
            {
                WorkspaceSelected = cmb_workspace.Text;
                indexSelected = cmb_workspace.SelectedIndex;
                this.Cursor = Cursors.WaitCursor;
                
                ((RallyDesk)parent).toolStripStatusLabel.Text = "Selecting Workspace...";
                ((RallyDesk)parent).ProgressBarMain.Style = ProgressBarStyle.Marquee;
                ((RallyDesk)parent).ProgressBarMain.Visible = true;

                Utilities.SelectWork(WorkspaceSelected, indexSelected);
                Utilities.SetProjects();
                ((RallyDesk)parent).ProgressBarMain.Visible = false;
                ((RallyDesk)parent).toolStripStatusLabel.Text = "Ready";

               
                this.Cursor = Cursors.Default;
                this.Close();                         
            }
        }

       

        private void cmb_workspace_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cmb_workspace.Text != string.Empty)
                if(!(this.cmb_workspace.Text.Equals(RallyDesk.CURRENTWORKSPACE.SelectedWorkSpace)))
                this.button1.Enabled = true;
            else
                this.button1.Enabled = false;
        }

        private void cmb_workspace_SelectedValueChanged(object sender, EventArgs e)
        {
            if (this.cmb_workspace.Text != string.Empty)
                if (!(this.cmb_workspace.Text.Equals(RallyDesk.CURRENTWORKSPACE.SelectedWorkSpace)))
                this.button1.Enabled = true;
            else
                this.button1.Enabled = false;
        }
    
        


        private void cmb_workspace_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if(this.button1.Enabled == true) 
                this.button1.PerformClick();
            }
        }
          
    }
}